// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.IndexManagement
{
	public sealed partial class IndexSettingsAnalysis
	{
		[JsonInclude]
		[JsonPropertyName("analyzer")]
		public Elastic.Clients.Elasticsearch.Analysis.Analyzers? Analyzer { get; set; }

		[JsonInclude]
		[JsonPropertyName("char_filter")]
		public Dictionary<string, Elastic.Clients.Elasticsearch.Analysis.CharFilter>? CharFilter { get; set; }

		[JsonInclude]
		[JsonPropertyName("filter")]
		public Dictionary<string, Elastic.Clients.Elasticsearch.Analysis.TokenFilter>? Filter { get; set; }

		[JsonInclude]
		[JsonPropertyName("normalizer")]
		public Elastic.Clients.Elasticsearch.Analysis.Normalizers? Normalizer { get; set; }

		[JsonInclude]
		[JsonPropertyName("tokenizer")]
		public Dictionary<string, Elastic.Clients.Elasticsearch.Analysis.Tokenizer>? Tokenizer { get; set; }
	}

	public sealed partial class IndexSettingsAnalysisDescriptor : SerializableDescriptorBase<IndexSettingsAnalysisDescriptor>
	{
		internal IndexSettingsAnalysisDescriptor(Action<IndexSettingsAnalysisDescriptor> configure) => configure.Invoke(this);
		public IndexSettingsAnalysisDescriptor() : base()
		{
		}

		private Elastic.Clients.Elasticsearch.Analysis.Analyzers? AnalyzerValue { get; set; }

		private Dictionary<string, Elastic.Clients.Elasticsearch.Analysis.CharFilter>? CharFilterValue { get; set; }

		private Dictionary<string, Elastic.Clients.Elasticsearch.Analysis.TokenFilter>? FilterValue { get; set; }

		private Elastic.Clients.Elasticsearch.Analysis.Normalizers? NormalizerValue { get; set; }

		private Dictionary<string, Elastic.Clients.Elasticsearch.Analysis.Tokenizer>? TokenizerValue { get; set; }

		public IndexSettingsAnalysisDescriptor Analyzer(Elastic.Clients.Elasticsearch.Analysis.Analyzers? analyzer)
		{
			AnalyzerValue = analyzer;
			return Self;
		}

		public IndexSettingsAnalysisDescriptor Analyzer(Analysis.AnalyzersDescriptor descriptor)
		{
			AnalyzerValue = descriptor.PromisedValue;
			return Self;
		}

		public IndexSettingsAnalysisDescriptor Analyzer(Action<Analysis.AnalyzersDescriptor> configure)
		{
			var descriptor = new Analysis.AnalyzersDescriptor();
			configure?.Invoke(descriptor);
			AnalyzerValue = descriptor.PromisedValue;
			return Self;
		}

		public IndexSettingsAnalysisDescriptor CharFilter(Func<FluentDictionary<string, Elastic.Clients.Elasticsearch.Analysis.CharFilter>, FluentDictionary<string, Elastic.Clients.Elasticsearch.Analysis.CharFilter>> selector)
		{
			CharFilterValue = selector?.Invoke(new FluentDictionary<string, Elastic.Clients.Elasticsearch.Analysis.CharFilter>());
			return Self;
		}

		public IndexSettingsAnalysisDescriptor Filter(Func<FluentDictionary<string, Elastic.Clients.Elasticsearch.Analysis.TokenFilter>, FluentDictionary<string, Elastic.Clients.Elasticsearch.Analysis.TokenFilter>> selector)
		{
			FilterValue = selector?.Invoke(new FluentDictionary<string, Elastic.Clients.Elasticsearch.Analysis.TokenFilter>());
			return Self;
		}

		public IndexSettingsAnalysisDescriptor Normalizer(Elastic.Clients.Elasticsearch.Analysis.Normalizers? normalizer)
		{
			NormalizerValue = normalizer;
			return Self;
		}

		public IndexSettingsAnalysisDescriptor Normalizer(Analysis.NormalizersDescriptor descriptor)
		{
			NormalizerValue = descriptor.PromisedValue;
			return Self;
		}

		public IndexSettingsAnalysisDescriptor Normalizer(Action<Analysis.NormalizersDescriptor> configure)
		{
			var descriptor = new Analysis.NormalizersDescriptor();
			configure?.Invoke(descriptor);
			NormalizerValue = descriptor.PromisedValue;
			return Self;
		}

		public IndexSettingsAnalysisDescriptor Tokenizer(Func<FluentDictionary<string, Elastic.Clients.Elasticsearch.Analysis.Tokenizer>, FluentDictionary<string, Elastic.Clients.Elasticsearch.Analysis.Tokenizer>> selector)
		{
			TokenizerValue = selector?.Invoke(new FluentDictionary<string, Elastic.Clients.Elasticsearch.Analysis.Tokenizer>());
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (AnalyzerValue is not null)
			{
				writer.WritePropertyName("analyzer");
				JsonSerializer.Serialize(writer, AnalyzerValue, options);
			}

			if (CharFilterValue is not null)
			{
				writer.WritePropertyName("char_filter");
				JsonSerializer.Serialize(writer, CharFilterValue, options);
			}

			if (FilterValue is not null)
			{
				writer.WritePropertyName("filter");
				JsonSerializer.Serialize(writer, FilterValue, options);
			}

			if (NormalizerValue is not null)
			{
				writer.WritePropertyName("normalizer");
				JsonSerializer.Serialize(writer, NormalizerValue, options);
			}

			if (TokenizerValue is not null)
			{
				writer.WritePropertyName("tokenizer");
				JsonSerializer.Serialize(writer, TokenizerValue, options);
			}

			writer.WriteEndObject();
		}
	}
}